home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / GRAPHICS / GRAPHUTL / 2296.ZIP / PLSRC18.ZIP / PICLAB.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-03-10  |  12.1 KB  |  368 lines

  1. /* PICLAB.H : Constants, types, and globals for PICLAB are defined.  This
  2. ** file is included by all modules, so initializers are enclosed in "#ifdef
  3. ** MAIN_MODULE" blocks.
  4. */
  5.  
  6. #include <limits.h>
  7. #include <setjmp.h>
  8.  
  9. #ifndef UTYPEDEFS
  10.     #include "typedefs"
  11. #endif
  12.  
  13. #define VERSION "1.81"
  14.  
  15. /* #define TEST    1 */
  16.  
  17. #define UTYPE   0       /* Used in vartable[]       */
  18. #define FTYPE   1
  19. #define STYPE   2
  20. #define BTYPE   3
  21. #define LTYPE   4
  22. #define STRSIZE 32
  23. #define BUFSIZE 8192
  24. #define NFILES  6       /* Max number of open files */
  25. #define NIMAGES 3       /* number of edit buffers   */
  26. #define READ    1
  27. #define WRITE   2
  28.  
  29. GLOBAL struct _ioblk {                  /* This structure and the following */
  30.     int handle, width, mode;            /* prototypes are used in PLFILES.C */
  31.     U16 bsize, bufp, bfull;
  32.     U8 *iobuf, *linebuf;
  33.     char fname[65];
  34. } ioblocks[NFILES];
  35.  
  36. GLOBAL struct _imgbuf {
  37.     char *bufname, *filename;
  38.     U8    flags,        /* bit 0 = raster order, bit 1 = mapped */
  39.         planes;
  40.     U16 width, height;
  41. } images[NIMAGES], *old, *new, *itmp;
  42.  
  43. GLOBAL struct _plane {
  44.     U8 *linebuf;
  45.     int handle;
  46.     U16 width;
  47. } planes[NFILES];
  48.  
  49. GLOBAL int p_argc INIT(0);
  50. GLOBAL char *p_argv[10];
  51.  
  52. int vtype(void);
  53. char *makepath(char *, char *, char *);
  54. int p_closeall(void);
  55. int p_open(char *, char *, int, int, int);
  56. int p_reopen(int, int);
  57. int p_seek(int, long);
  58. void p_close(int);
  59. int p_getc(int);
  60. char *p_gets(char *, int, int);
  61. int p_getline(int, int);
  62. int p_putline(int, int);
  63. struct _plane *openplane(int, struct _imgbuf *, int);
  64. void closeplane(struct _plane *);
  65. int getline(struct _plane *);
  66. int putline(struct _plane *);
  67. int seekline(struct _plane *, int);
  68. int begintransform(void);
  69.  
  70. #define linebuf(h) ioblocks[h].linebuf
  71.  
  72. char *talloc(U16);              /* Memory allocation functions in MEMORY.C  */
  73. U32 mark(void);
  74. void release(U32);
  75. void releaseall(void);
  76. U32 freemem(void);
  77.  
  78. GLOBAL U8 *rv, *gv, *bv, *table2;   /* Interface to routines in PLDITHER.C  */
  79. GLOBAL int startdither INIT(1);
  80. void ditherline(U16, U8 *[3], U8 *);
  81. void bitmapline(U16, U8 *, U8 *[2]);
  82. void scaleline(U8 *, U8 *, int, int);
  83.  
  84. typedef struct _arg {           /* Structure passed to command-handlers     */
  85.     char *cval;
  86.     float fval;
  87. } argument;
  88.  
  89. int addimg(int, argument *);        /* Command-handling routines.  These    */
  90. int average(int, argument *);       /* should all take a count of arguments */
  91. int brightness(int, argument *);    /* and a pointer to an array of them.   */
  92. int clip(int, argument *);          /* To add a command to PICLAB, write a  */
  93. int color(int, argument *);         /* function using these as a guide, put */
  94. int contrast(int, argument *);      /* a prototype here, and add an entry   */
  95. int expand(int, argument *);        /* to cmdtable[], below.                */
  96. int filedir(int, argument *);
  97. int gamma(int, argument *);
  98. int gifdir(int, argument *);
  99. int grayscale(int, argument *);
  100. int help(int, argument *);
  101. int histogram(int, argument *);
  102. int list(int, argument *);
  103. int load(int, argument *);
  104. // int loadbmp(int, argument *);
  105. int loadpal(int, argument *);
  106. int loadgif(int, argument *);
  107. int loadtga(int, argument *);
  108. int loadrix(int, argument *);
  109. int loadraw(int, argument *);
  110. int loadip(int, argument *);
  111. int makepal(int, argument *);
  112. int egapal(int, argument *);
  113. int map(int, argument *);
  114. int median(int, argument *);
  115. int mirror(int, argument *);
  116. int negate(int, argument *);
  117. int overlay(int, argument *);
  118. int pause(int, argument *);
  119. int printpic(int, argument *);
  120. int quit(int, argument *);
  121. int rescale(int, argument *);
  122. int reverse(int, argument *);
  123. int rotate(int, argument *);
  124. int run(int, argument *);
  125. int save(int, argument *);
  126. // int savebmp(int, argument *);
  127. int savepal(int, argument *);
  128. int savegif(int, argument *);
  129. int savetga(int, argument *);
  130. int saverix(int, argument *);
  131. int saveraw(int, argument *);
  132. int saveip(int, argument *);
  133. int setvar(int, argument *);
  134. int sharpen(int, argument *);
  135. int shell(int, argument *);
  136. int showpic(int, argument *);
  137. int smooth(int, argument *);
  138. int subimg(int, argument *);
  139. #ifdef TEST
  140.   void testfunc(int, argument *);
  141. #endif
  142. int tgadir(int, argument *);
  143. int transform(int, argument *);
  144. int undo(int, argument *);
  145. int unmap(int, argument *);
  146.  
  147. void cgaline(int, U8 *);
  148. void egaline(int, U8 *);
  149. void vga1line(int, U8 *);        /* Video adapter- and mode-dependent        */
  150. void vga2line(int, U8 *);        /* routines from PLSHOW.C.                  */
  151. void svga640line(int, U8 *);
  152. void svga800line(int, U8 *);
  153.  
  154. void pl_warn(int);                            /* General-purpose routines     */
  155. int pl_printf(char *, ...);                    /* from PLMAIN.C                */
  156. int pl_sprintf(char *, char *, ...);
  157. void pl_init(void);
  158. void pl_trace(register int);
  159. void pl_cleanup(void);
  160. int pl_match(char *, char *[]);
  161. int pl_parse(char *);
  162. int initfile(void);
  163. void main(int argc, char *argv[]);
  164.  
  165. int pjprint(void);
  166. int ljprint(void);
  167.  
  168. GLOBAL jmp_buf interp;
  169.  
  170. GLOBAL struct {                         /* This table is used by parse() to */
  171.     char *command;                      /* dispatch commands to the correct */
  172.     int (*function)(int, argument *);   /* function.  Each is responsible   */
  173.     U16 fileoff;                        /* for interpreting the arguments   */
  174. } cmdtable[]                            /* passed to it; see the individual */
  175.                                         /* source files for more details.   */
  176. #ifdef MAIN_MODULE                      
  177.     = { { "ADD",        addimg,        0 },
  178.         { "AVERAGE",    average,    0 },
  179.         { "BRIGHTEN",   brightness, 0 },
  180.         { "CALL",       shell,      0 },
  181.         { "CANCEL",     undo,       0 },
  182.         { "CLIP",       clip,       0 },
  183.         { "COLOR",      color,      0 },
  184.         { "CONTRAST",   contrast,   0 },
  185.         { "DARKEN",     brightness, 0 },
  186.         { "DIR",        filedir,    0 },
  187.         { "DOS",        shell,      0 },
  188.         { "EGAPAL",        egapal,        0 },
  189.         { "EXIT",       quit,       0 },
  190.         { "EXPAND",     expand,     0 },
  191.         { "GAMMA",      gamma,      0 },
  192.         { "GDIR",       gifdir,     0 },
  193.         { "GLOAD",      loadgif,    0 },
  194.         { "GRAY",       grayscale,  0 },
  195.         { "GSAVE",      savegif,    0 },
  196.         { "HELP",        help,        0 },
  197.         { "HISTOGRAM",  histogram,  0 },
  198.         { "LIST",       list,       0 },
  199.         { "LOAD",       load,       0 },
  200.         { "MAKEPAL",    makepal,    0 },
  201.         { "MAP",        map,        0 },
  202.         { "MEDIAN",     median,     0 },
  203.         { "MIRROR",     mirror,     0 },
  204.         { "NEGATE",     negate,     0 },
  205.         { "OVERLAY",    overlay,    0 },
  206.         { "PAUSE",      pause,      0 },
  207.         { "PLOAD",        loadpal,    0 },
  208.         { "PRINT",      printpic,   0 },
  209.         { "PSAVE",        savepal,    0 },
  210.         { "QUIT",       quit,       0 },
  211.         { "RESCALE",    rescale,    0 },
  212.         { "REVERSE",    reverse,    0 },
  213.         { "RLOAD",        loadraw,    0 },
  214.         { "ROTATE",     rotate,     0 },
  215.         { "RSAVE",        saveraw,    0 },
  216.         { "RUN",        run,        0 },
  217.         { "SAVE",       save,       0 },
  218.         { "SET",        setvar,     0 },
  219.         { "SHARPEN",    sharpen,    0 },
  220.         { "SHELL",      shell,      0 },
  221.         { "SHOW",       showpic,    0 },
  222.         { "SMOOTH",     smooth,     0 },
  223.         { "SUBTRACT",   subimg,     0 },
  224.         { "TDIR",       tgadir,     0 },
  225.         { "TLOAD",      loadtga,    0 },
  226.         { "TRANSFORM",  transform,  0 },
  227.         { "TSAVE",      savetga,    0 },
  228.         { "UNDO",       undo,       0 },
  229.         { "UNMAP",        unmap,        0 },
  230.         { NULL,         NULL,        0 } }
  231. #endif
  232.     ;
  233.  
  234. GLOBAL struct {
  235.     char *name;
  236.     int (*loadf)(int, argument *),
  237.         (*savef)(int, argument *);
  238.     U16 fileoff;
  239. } formats[]
  240.  
  241. #ifdef MAIN_MODULE
  242.     = { { "TARGA",      loadtga,    savetga,    0 },
  243. //        { "BITMAP",        loadbmp,    savebmp,    0 },
  244. //        { "PICTOR",        loadpic,    savepic,    0 },
  245. //        { "PCX",        loadpcx,    savepcx,    0 },
  246.         { "GIF",        loadgif,    savegif,    0 },
  247.         { "RIX256",     loadrix,    saverix,    0 },
  248.         { "RAW",        loadraw,    saveraw,    0 },
  249.         { "IP",         loadip,     saveip,        0 },
  250.         { NULL,         NULL,       NULL,        0 } }
  251. #endif
  252.     ;
  253.  
  254. GLOBAL struct {
  255.     char *name;
  256.     U16 width, height;
  257.     U16 pax, pbx;
  258.     void (*linefunc)(int, U8 *);
  259.     U16 fileoff;
  260.     char ctype;
  261.     char *comment;
  262. } displays[]
  263.  
  264. #ifdef MAIN_MODULE
  265. = {    { "CGA",    320, 200, 0x06,      0,    cgaline,    0,    0,    "Dithered CGA mono" },
  266.     { "EGA",    640, 350, 0x10,      0,    egaline,    0,    1,    "8-color EGA dither" },
  267.     { "VGA1",    320, 200, 0x13,      0,    vga1line,    0,    2,    "Standard VGA" },
  268.     { "VGA2",    640, 480, 0,      8,    vga2line,    0,    2,    "Simulated on VGA" },
  269.     { "SVGA1",    640, 400, 0,      1,    svga640line,0,  2,  "For 256k SVGAs" },
  270.     { "SVGA2",    640, 480, 0,      2,    svga640line,0,  2,  "For 512k SVGAs" },
  271.     { "SVGA3",    800, 600, 0,      3,    svga800line,0,    2,    "For 512k SVGAs" },
  272.  
  273.     { NULL,        0,     0,      0,      0,    NULL,        0,    0,    NULL } }
  274. #endif
  275.     ;
  276.  
  277. GLOBAL struct {
  278.     char *name;
  279.     int (*printfunc)(void);
  280.     U16 fileoff;
  281. } printers[]
  282.  
  283. #ifdef MAIN_MODULE
  284. = { { "PAINTJET",    pjprint,    0 },
  285.     { "LASERJET",    ljprint,    0 },
  286. //    { "EPSON",        epsonprint,    0 },
  287.     { NULL,            NULL,        0 } }
  288. #endif
  289.     ;
  290.  
  291. GLOBAL U8   lookup[3][256], gcmap[3][256]
  292. #ifdef MAIN_MODULE
  293.     = { 0, 0, 0, 0, 0, 255, 0, 255, 0, 0, 255, 255, 255,
  294.         0, 0, 255, 0, 255, 255, 255, 0, 255, 255, 255 }
  295. #endif
  296. ;
  297.  
  298. GLOBAL U32  hist[3][256],
  299.             minalloc            INIT(100000L);
  300. GLOBAL int  leavetemps          INIT(0),
  301.             dither                INIT(1),
  302.             bleed               INIT(70),
  303.             laserdpi            INIT(300),
  304.             histvalid           INIT(0),
  305.             transpend           INIT(0),
  306.             multiimage          INIT(0),
  307.             multimap            INIT(0),
  308.             silent                INIT(0),
  309.             debug                INIT(0);
  310. GLOBAL U16  quitflag            INIT(0),
  311.             helploaded            INIT(0),
  312.             printscale            INIT(1),
  313.             interactive         INIT(1),
  314.             xorigin             INIT(0),
  315.             yorigin             INIT(0),
  316.             palette             INIT(256),
  317.             crez                INIT(8);
  318. GLOBAL char printer[STRSIZE]    INIT("LASERJET"),
  319.             printfile[STRSIZE]  INIT(""),
  320.             picdir[STRSIZE]     INIT(""),
  321.             helpfile[STRSIZE]    INIT("PL.HLP"),
  322.             fileformat[STRSIZE] INIT("TARGA"),
  323.             display[STRSIZE]    INIT(""),
  324.             tempdir[STRSIZE]    INIT(""),
  325.             version[]           INIT(VERSION);
  326.  
  327. GLOBAL struct _vars {       /* This table is used by the SET command.  See  */
  328.     char *varname;          /* SETVAR.C for more details.                   */
  329.     char *varaddr;
  330.     char vartype;
  331.     char visible;
  332.     U16 fileoff;
  333. } vartable[]
  334.  
  335. #ifdef MAIN_MODULE
  336.     = { { "XORIGIN",    (char*)&xorigin,    UTYPE,    1,    0 },
  337.         { "YORIGIN",    (char*)&yorigin,    UTYPE,    1,    0 },
  338.         { "PALETTE",    (char*)&palette,    UTYPE,    1,    0 },
  339.         { "CREZ",       (char*)&crez,       UTYPE,    1,    0 },
  340.         { "DPI",        (char*)&laserdpi,   UTYPE,    1,    0 },
  341.         { "MULTIIMAGE", (char*)&multiimage, BTYPE,    1,    0 },
  342.         { "MULTIMAP",   (char*)&multimap,   BTYPE,    1,    0 },
  343.         { "DITHER",        (char*)&dither,        BTYPE,    1,    0 },
  344.         { "DISPLAY",    display,            STYPE,    1,    0 },
  345.         { "PRINTER",    printer,            STYPE,    1,    0 },
  346.         { "PRINTFILE",  printfile,          STYPE,    1,    0 },
  347.         { "PRINTSCALE",    (char*)&printscale,    UTYPE,    1,    0 },
  348.         { "TEMPDIR",    tempdir,            STYPE,    1,    0 },
  349.         { "PICDIR",     picdir,             STYPE,    1,    0 },
  350.         { "FILEFORMAT", fileformat,         STYPE,    1,    0 },
  351.  
  352.         { "DEBUG",        (char*)&debug,        UTYPE,    0,    0 },
  353.         { "SILENT",        (char*)&silent,        BTYPE,    0,    0 },
  354.         { "LEAVETEMPS", (char*)&leavetemps, BTYPE,    0,    0 },
  355.         { "HELPFILE",    helpfile,            STYPE,    0,    0 },
  356.  
  357.         { NULL,         NULL,               0,        0,    0 } }
  358. #endif
  359.     ;
  360.  
  361. GLOBAL char reading[]   INIT("Reading %s...\r\n"),
  362.             writing[]   INIT("Writing %s...\r\n"),
  363.             working[]   INIT("Working...\r\n"),
  364.             maperr[]    INIT("This process cannot be performed on mapped images.\r\n"
  365.                              "Use the UNMAP or GRAY commands and try again.\r\n"),
  366.             done[]      INIT("\rDone.    \r\n"),
  367.             crlf[]        INIT("\r\n");
  368.